﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Sparkle.UI;

namespace Sparkle.SL.Demo.UI
{
    /// <summary>
    /// Interaction logic for ObjectSelector.xaml
    /// </summary>
    public partial class ObjectSelector : UserControl
    {
        public ObjectSelector()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(ObjectSelector_Loaded);
           // DataContextChanged += new DependencyPropertyChangedEventHandler(ObjectSelector_DataContextChanged);
        }

        void ObjectSelector_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (this.DataContext != null)
            {
                this.txtBlockMain.Text = this.DataContext.ToString();
            }
        }

        void ObjectSelector_Loaded(object sender, RoutedEventArgs e)
        {
            ;
        }
    }

    public class GenericObjectSelector : UserControl, IFullWidth
    {
        private ObjectSelector _objectSelector = new ObjectSelector();

        public GenericObjectSelector()
        {
            Loaded += new RoutedEventHandler(GenericObjectSelector_Loaded);
        }

        void GenericObjectSelector_Loaded(object sender, RoutedEventArgs e)
        {
            this.Content =_objectSelector;
            //this.DataContextChanged += new DependencyPropertyChangedEventHandler(GenericObjectSelector_DataContextChanged);
            this.SizeChanged += new SizeChangedEventHandler(GenericObjectSelector_SizeChanged);
        }

        void GenericObjectSelector_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            _objectSelector.Width = this.Width;
        }

        void GenericObjectSelector_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            _objectSelector.DataContext = this.DataContext;    
        }       
    }
}
